<%--
  Created by IntelliJ IDEA.
  User: hp
  Date: 2018/12/28
  Time: 16:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>库存增加</title>
    <jsp:include page="${pageContext.request.contextPath}/common/tag.jsp"/>
</head>
<script>
    $(function () {
        $.post("${pageContext.request.contextPath}/fenlei/queryfenlei",function (data) {
            $.each(data,function (index,item) {
                $("#typeid").append("<option value=\""+item.fid+"\">"+item.fname+"</option>")
            })
        });
        /*绑定下拉数据*/
        $.post("${pageContext.request.contextPath}/shopcontrllo/query",function (data) {
            $.each(data,function (index,item) {
                $("#shopid").append("<option value=\""+item.shopId+"\">"+item.shopName+"</option>")
            })
        });
        /*绑定供货商*/
        $.post("${pageContext.request.contextPath}/supplier/getIdAndName",function (data) {
            $.each(data,function (index,item) {
                $("#ghshang").append("<option value=\""+item.id+"\">"+item.gname+"</option>");
            })
        });

        /*获得入库类别的类型*/
        $.post("${pageContext.request.contextPath}/rkfenlei/queryjin",function (data) {
            $.each(data,function (index,item) {
                $("#rukuleibie").append("<input type=\"radio\" name=\"rukuleibie\" value=\""+item.rkid+"\"><label>"+item.rkname+"</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;")
            })
            //console.log(data);
        })
        /*绑定类型下拉框*/
       /* $.post("{pageContext.request.contextPath}/fenlei/queryfenlei",function (data) {
            $.each(data,function (index,item) {
                $("#type").append("<option value=\""+item.fid+"\">"+item.fname+"</option>");
                $("#fenlei").append("<option value=\""+item.fid+"\">"+item.fname+"</option>");
            })
        });*/
        /*绑定单价选择单位的下拉框*/
        /*$.post("{pageContext.request.contextPath}/company/querydanwei",function (data) {
            $.each(data,function (index,item) {
                $("#danwei").append("<option value=\""+item.cid+"\">"+item.cname+"</option>");
            })
        });*/
        /*table表格*/
       /* $("#shoptable").bootstrapTable({
            url : '{pageContext.request.contextPath}/shop/query', //路径
            toolbar : '#add,#pldel',
            pageSize : 5, //设置每页显示的行数
            pageList:[2,4,8,16], //设置可供选择的页面数据条数
            pageNumber:1, //如果设置了分页，首页页码。
            height : 420,  //表格高度
            pagination : true, //开启分页  默认情况下，是客户端分页的
            sidePagination:'server',  //启用服务器端分页
            queryParams:function(params){
                var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    limit: params.limit,  //页面大小
                    offset: params.offset, //页码
                    sName:$("#shopname").val(),
                    typeid:$("#type").val()
                };
                return temp;
            },
            columns : [
                {checkbox : true},
                {field : 'id',title : '商品编号',align : 'center'},
                {field : 'sName',title : '商品名称',align : 'center'},
                {field : 'speci',title : '规格',align : 'center'},
                {field : 'fname',title : '商品类型',align : 'center'},
                {field : 'goldMoney',title : '进价',align : 'center'},
                {field : 'saleMoney',title : '销售价',align : 'center'},
                {field : 'stockNum',title : '库存',align : 'center'},
                {field : 'cname',title : '商品单位',align : 'center'},
                {title : '操作',align : 'center',
                    formatter : function (value,row,index) {
                        return "<button class=\"btn btn-primary\" data-toggle=\"modal\" href=\"#shopmodal\" onclick='huoqu("+row.id+")'>修改</button>&nbsp;&nbsp;<button class=\"btn btn-primary\" onclick='del("+row.id+","+row.stockNum+")'>删除</button>"

                    }
                }
            ],
            onClickRow : function(row, $element){

                var index = $element.data('index');
                $("#shoptable").bootstrapTable("uncheckAll");
                console.log(row);
                //选中要修改的行
                $("#shoptable").bootstrapTable("check",index);
                $("#dianpunone").show();
                $("#sid").val(row.id);
                $("#danjia").val(row.goldMoney);
                $("#guige").val(row.speci);
                $("#sname").val(row.sName);
                $("#shoujia").val(row.saleMoney);
                $("#addfenshop div").remove();
                $.post("{pageContext.request.contextPath}/kucun/queryAddkcShop",{"sid":row.id},function (data) {
                    $.each(data,function (index,item) {
                        $("#addfenshop").append("" +
                            "<div>\n" +
                            "                          <input type=\"checkbox\" onclick='checkboxOnclick(this)' name=\"ckbox\" value=\""+item.shopId+"\">"+item.shop.shopName+"<span style=\"margin-left: 20px;\">[当前数量]："+item.stockNum+" <span style=\"margin-left: 20px;\">[变动数量]：</span></span><input type=\"text\" name=\"shuliang\" size=\"4\">\n" +
                            "                      </div>")
                    })
                    console.log(data);
                })
            }
        }) ;*/

        /*信息表单*/
        $("#mytable").bootstrapTable({
            url : '${pageContext.request.contextPath}/kucun/query',
            toolbar : '#addkucun',
            pageSize : 5,
            pageList : [2,4,8,16],
            pageNumber : 1,
            height : 420,
            pagination : true,
            sidePagination:'server',  //启用服务器端分页
            queryParams:function(params){
                var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    limit: params.limit,  //页面大小
                    offset: params.offset, //页码
                    name:$("#shopname").val(),
                    typeid:$("#typeid").val(),
                    shopid:$("#shopid").val()
                };
                return temp;
            },
            columns : [
                {checkbox : true},
                //{field : 'kid',title : '编号',align : 'center'},
                {field : 'sid',title : '商品编号',align : 'center'},
                {field : 'sname',title : '商品名称',align : 'center'},
                {field : 'kpeci',title : '规格',align : 'center'},
                {field : 'fenlei.fname',title : '分类',align : 'center'},
                {field : 'goldMoney',title : '进价',align : 'center'},
                {field : 'saleMoney',title : '售价',align : 'center'},
                {field : 'stockNum',title : '库存数量',align : 'center'},
                {field : 'costMoney',title : '成本金额',align : 'center'},
                {field : 'shop.shopName',title : '店铺',align : 'center'},
                /*{title:'操作',align:'center',
                    formatter : function (index,row,value) {
                        return "<button class='btn btn-primary' onclick=\"updateMoney("+row.kid+",'"+row.sname+"',"+row.goldMoney+","+row.stockNum+")\">修改进价</button>&nbsp;&nbsp;&nbsp;" +
                            "<button class='btn btn-primary'>修改</button>"
                    }
                }*/
            ],
            onClickRow : function(row, $element){

                var index = $element.data('index');
                $("#mytable").bootstrapTable("uncheckAll");
                console.log(row);
                //选中要修改的行
                $("#mytable").bootstrapTable("check",index);
                $("#dianpunone").show();
                $("#sid").val(row.sid);
                $("#danjia").val(row.goldMoney);
                $("#guige").val(row.kpeci);
                $("#sname").val(row.sname);
                $("#shoujia").val(row.saleMoney);
                $("#kucunid").val(row.kid);
                $("#addfenshop div").remove();
                $.post("${pageContext.request.contextPath}/kucun/queryAddkcShop",{"kid":row.kid},function (data) {
                    $.each(data,function (index,item) {
                        $("#addfenshop").append("" +
                            "<div>\n" +
                            "                          <input type=\"hidden\" name=\"ckbox\" value=\""+item.shopId+"\">"+item.shop.shopName+"<span style=\"margin-left: 20px;\">[当前数量]："+item.stockNum+" <span style=\"margin-left: 20px;\">[变动数量]：</span></span><input type=\"text\" name=\"shuliang\" size=\"4\">\n" +
                            "                      </div>")
                    })
                    console.log(data);
                })
            }
        })

    })
</script>
<body>
    <div class="">
      <%--  <button id="add" onclick="addinfo()" class="btn btn-primary" data-toggle="modal" href="#shopmodal">添加</button>&nbsp;&nbsp;
        <button id="pldel" onclick="pldel()" class="btn btn-primary" style="margin-left: 20px;">批量删除</button>--%>
        <%--<form class="form-inline" style="margin-top: 20px;text-align: right">
            <div class="form-group">
                <label style="font-size: 15px;">商品类别：</label>&nbsp;
                <select name="name" id="type" class="form-control">
                    <option value="0">请选择</option>
                </select>
            </div> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <div class="form-group">
                <label for="shopname">商品名称：</label>&nbsp;
                <input type="text" class="form-control" id="shopname" placeholder="双汇火腿" style="height: 40px;">
            </div>
            <button onclick="serch();" class="btn btn-primary btn-lg" type="button"><span class="glyphicon glyphicon-search">搜索</span></button>
        </form>
        <table id="shoptable"></table>--%>
          <form class="form-inline" style="margin-top: 20px;text-align: right">
              <div class="form-group">
                  <label style="font-size: 15px;">商品分类：</label>&nbsp;
                  <select name="type" id="typeid" class="form-control">
                      <option value="0">全部</option>
                  </select>
              </div> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <div class="form-group">
                  <label style="font-size: 15px;">店铺：</label>&nbsp;
                  <select name="shop" id="shopid" class="form-control">
                      <option value="0">全部</option>
                  </select>
              </div> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <div class="form-group">
                  <label for="shopname">商品名称：</label>&nbsp;
                  <input type="text" class="form-control" id="shopname" placeholder="三只松鼠" style="height: 40px;">
              </div>
              <button onclick="serch();" class="btn btn-primary btn-lg" type="button"><span class="glyphicon glyphicon-search">搜索</span></button>
          </form>
          <%--<button class="btn btn-primary" id="addkucun" onclick="addmodal()">添加</button>--%>
          <table id="mytable"></table>

          <form action="" id="addkucunform" method="post" class="form-horizontal" role="form">
              <div class="form-group">
                  <h1 style="text-align: center;">库存增加</h1>
              </div>
              <div class="form-group">
                  <label for="sid" class="control-label col-sm-1">入库商品：</label>
                  <div class="col-sm-3">
                      <input type="hidden" name="kucunid" id="kucunid" value="">
                      <input type="text" class="form-control" id="sid" disabled="disabled" style="background: white">
                  </div>
                  <label for="danjia" class="control-label col-sm-2">入库单价：</label>
                  <div class="col-sm-2">
                      <input type="text" class="form-control" id="danjia" disabled="disabled" style="background: white">
                  </div>
                  <label for="guige" class="control-label col-sm-1">规格：</label>
                  <div class="col-sm-2">
                      <input type="text" class="form-control" id="guige" disabled="disabled" style="background: white">
                  </div>
              </div>
              <div class="form-group" style="margin-top: 20px;">
                  <label for="sname" class="control-label col-sm-1">入库名称：</label>
                  <div class="col-sm-3">
                      <input type="text" class="form-control" id="sname" style="background: white;" disabled="disabled">
                  </div>
                  <label for="shoujia" class="control-label col-sm-2">商品售价：</label>
                  <div class="col-sm-2">
                      <input type="text" class="form-control" id="shoujia" disabled="disabled" style="background: white;">
                  </div>
                  <label class="control-label col-sm-1">供货商：</label>
                  <div class="col-sm-2">
                      <select name="supller" id="ghshang" class="form-control">
                          <option value="0">请选择</option>
                      </select>
                  </div>
              </div>
              <div class="form-group" style="margin-top: 20px;">
                  <label class="control-label col-sm-1">入库类别：</label>
                  <div class="col-sm-5" id="rukuleibie">
                      <%--<input type="radio" name="rukuleibie" value="1" id="jinhuo"><label for="jinhuo">采购进货</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                      <input type="radio" name="rukuleibie" value="2" id="baoyi"><label for="baoyi">商品报溢</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                      <input type="radio" name="rukuleibie" value="3" id="huanhuo"><label for="huanhuo">商品还货</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                      <input type="radio" name="rukuleibie" value="4" id="qita"><label for="qita">其他入库</label>--%>
                  </div>
              </div>
              <div class="form-group" id="dianpunone" style="margin-top: 20px;display: none;">
                  <label class="control-label col-sm-1">所属店铺：</label>
                  <div class="col-sm-5" id="addfenshop">
                     <%-- <div>
                          <input type="checkbox" value="">总店 <span style="margin-left: 20px;">[当前数量]：88 <span style="margin-left: 20px;">[变动数量]：</span></span><input type="text" size="4">
                      </div>
                      <div>
                          <input type="checkbox">总店 <span style="margin-left: 20px;">[当前数量]：88 <span style="margin-left: 20px;">[变动数量]：</span></span><input type="text" size="4">
                      </div>--%>
                  </div>
              </div>
              <div class="form-group" style="margin-top: 20px;">
                  <label class="control-label col-sm-1">备注：</label>
                  <div class="col-sm-5">
                      <textarea name="" cols="42" rows="5" id="beizhu"></textarea>
                  </div>
                  <input type="button" class="btn-lg btn-primary col-sm-offse-1" onclick="tijiao()" value="提交" style="margin-top: 30px;">
              </div>
          </form>
    </div>
</body>
<script>
    /*点击搜索*/
    /*function serch() {
        //返回表格的 Options。
        var opts = $("#shoptable").bootstrapTable("getOptions") ;
        var limit = opts.pageSize ;
        var offset = (opts.pageNumber-1) * limit;
        var shopname = $("#shopname").val() ;
        var typeid = $("#type").val();
        $.post("{pageContext.request.contextPath}/shop/query",{'name':shopname,'typeid':typeid,'limit':limit,'offset':offset},function (data) {
            // var mydata = eval("("+data+")") ;
            //重新绑定表格数据
            $("#shoptable").bootstrapTable('load',data) ;
        })
    }*/
    function serch() {
        //返回表格的 Options。
        var opts = $("#mytable").bootstrapTable("getOptions") ;
        var limit = opts.pageSize ;
        var offset = (opts.pageNumber-1) * limit;
        var name = $("#shopname").val() ;
        var typeid = $("#typeid").val();
        var shopid = $("#shopid").val();
        $.post("${pageContext.request.contextPath}/kucun/query",{'name':name,'typeid':typeid,'shopid':shopid,'limit':limit,'offset':offset},function (data) {
            // var mydata = eval("("+data+")") ;
            //重新绑定表格数据
            $("#mytable").bootstrapTable('load',data) ;
        })
    }

    function tijiao() {
        var sid = $("#sid").val(); //商品编号
        var danjia = $("#danjia").val(); //商品进价
        var guige = $("#guige").val(); //商品规格
        var sname = $("#sname").val(); //商品名称
        var shoujia = $("#shoujia").val(); //商品名称
        var beizhu = $("#beizhu").val(); //备注
        var rk = val=$('input:radio[name="rukuleibie"]:checked').val(); //获得入库类别
        var ckbox =$("[name='ckbox']").val(); //店铺id
        var num = $("[name='shuliang']").val();//数量
        var ghshang = $("#ghshang").val();//供货商id
        var kucunid = $("#kucunid").val(); //库存id

        if(sname == ''){
            alert("请先选择商品");
            return false;
        } else if(rk==undefined){
            alert("请选择入库类型");
            return false;
        } else if(num==''){
            alert("请输入添加数量");
            return false;
        } else if(num==0){
            alert("数量不能为0");
            return false;
        } else if(ghshang == 0){
            alert("请选择供货商");
        }else{
            $.post("${pageContext.request.contextPath}/audit/insert",
                {"sid":sid,"kcid":kucunid,"jinjia":danjia,"sname":sname,"guige":guige,"rktype":rk,"dianpu":ckbox,"num":num,"ghs":ghshang,"beizhu":beizhu},function (data) {
                console.log(data);
                document.getElementById("addkucunform").reset();
                $("#dianpunone").hide();
                swal("提示信息", "提交成功，请等待审批!", "success");

            })
        }
    }
    /*$("#shoptable").on('dbl-click-row.bs.table',function ($event, field, value, row, target) {
        var index = target[0].parentElement.rowIndex;
        alert(index);
        console.log($event);
        /!*$("#shoptable").bootstrapTable("uncheckAll");
        //alert($element.id);
        //选中要修改的行
        $("#shoptable").bootstrapTable("check",$element.id-1);
        $("#dianpunone").show();
        /!*$("#sid").val(row.id);
        $("#danjia").val(row.goldMoney);
        $("#guige").val(row.speci);
        $("#sname").val(row.sName);*!/
        $("#shoujia").val(row.saleMoney);*!/
    })*/
</script>
</html>
